package org.xiaoxiao.servlet;

import org.xiaoxiao.dao.BookVoteDao;
import org.xiaoxiao.pojo.Book;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/index")
public class IndexServlet extends HttpServlet {
    private final BookVoteDao dao = new BookVoteDao();

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        // 获取所有书籍数据
        List<Book> books = dao.getAllBooks();
        request.setAttribute("books", books);
        
        // 转发到index.jsp
        request.getRequestDispatcher("/index.jsp").forward(request, response);
    }
}